package mytest;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @Author:wangbin.
 * @Description.
 * @Date:Created in 16:25 2017/10/19.
 * @Modified By:
 */
public class CustomizedRegistrationBean implements BeanDefinitionRegistryPostProcessor,InitializingBean,ApplicationContextAware,BeanNameAware {

    private ApplicationContext applicationContext = null;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
        System.out.println("========================:1" + "setApplicationContext");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("========================:2" + "afterPropertiesSet");
    }

    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
        RootBeanDefinition customizeClassBean = new RootBeanDefinition();
        customizeClassBean.setBeanClass(CustomizeClass.class);
        beanDefinitionRegistry.registerBeanDefinition("customizeClass",customizeClassBean);
        System.out.println("========================:3" + "postProcessBeanDefinitionRegistry");
        System.out.println(applicationContext.getBean("customizeClass"));
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
        System.out.println("=======================:"+"postProcessBeanFactory");
    }

    @Override
    public void setBeanName(String s) {

    }
}
